/*
 * 作者：姚俊
 * 功能：添加一个老师
 * 日期：2015-07-10
 */
package admin.action.teacher;

import teacher.bean.Teacher;
import admin.service.member.TeacherService;
import java.util.*;

public class AddTeacherAction {
	
	private Teacher teacher;
	private String flag;
	
	
	public Teacher getTeacher() {
		return teacher;
	}


	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	

	public String getFlag() {
		return flag;
	}


	public void setFlag(String flag) {
		this.flag = flag;
	}


	public String execute()
	{
		this.setFlag("succ");
		System.out.println("教师的工号为:"+this.getTeacher().getUser());
		//先检查工号有没有重复，之后才判断能不能添加
		List<Teacher> teachers=new TeacherService().getTeacherByAll(null, null, null);
		for(Teacher tea:teachers)
		{
			if(tea.getUser().equals(this.getTeacher().getUser()))
			{
				this.setFlag("err");
				System.out.println("进来了吗");
				break;
			}
		}
		if(this.getFlag().equals("succ"))
		{
			//当前密码为工号
			this.getTeacher().setPower(2);
			this.getTeacher().setPassword(this.getTeacher().getUser());
			new TeacherService().AddTeacher(this.getTeacher());
			System.out.println(this.getTeacher().getPower());
			System.out.println(this.getTeacher().getPassword());
		}
		return "succ";
	}

}
